export function getTree(data) {
    let result = [];
    let map = {};
    data.forEach(item => {
        map[item.id] = item;
    });
    data.forEach(item => {
        let parent = map[item.parentId];
        if (parent) {
            (parent.children || (parent.children = [])).push(item);
        } else {
            result.push(item);
        }
    });
    return result;
}
/* 评论树结构 */
export function commentTree(list){

  let rootList=list.filter(item=>{return item.parentId==null})
  for (let i = 0; i < rootList.length; i++) {
     rootList[i].children=[]
    for (let j = 0; j < list.length; j++) {
      if (rootList[i].id==list[j].parentId){
        rootList[i].children.push(list[j])
      }else {
          for (let k=0;k<rootList[i].children.length;k++){
            if (rootList[i].children[k].id==list[j].parentId){
              rootList[i].children.push(list[j])
            }
          }
      }
    }
  }

  return rootList
}